//
//  GTGuideBottomToolBar.m
//  GiftTalk
//
//  Created by Wan on 16/4/4.
//  Copyright © 2016年 Wan. All rights reserved.
//

#import "GTGuideBottomToolBar.h"
#import "GTGuideDetail.h"
#import "GTUMSocialShare.h"
#import "GTGuideDetailViewController.h"

@interface GTGuideBottomToolBar ()

@property (weak, nonatomic) IBOutlet UIButton *likeButton;
@property (weak, nonatomic) IBOutlet UIButton *shareButton;
@property (weak, nonatomic) IBOutlet UIButton *commentButton;

- (IBAction)likeButtonOnClick:(UIButton *)sender;
- (IBAction)shareButtonOnClick:(UIButton *)sender;
- (IBAction)commentButtonOnClick:(UIButton *)sender;

@end

@implementation GTGuideBottomToolBar

+ (instancetype)guideBottomToolBar
{
    return [self viewFromXib];
}

- (void)setGuideDetail:(GTGuideDetail *)guideDetail {
    _guideDetail = guideDetail;
    
    if (self.guideDetail.liked) {
        self.likeButton.selected = self.guideDetail.liked;
    }
    
    self.likeButton.titleLabel.text = [NSString stringWithFormat:@"%zd",self.guideDetail.likes_count];
    self.shareButton.titleLabel.text = [NSString stringWithFormat:@"%zd",self.guideDetail.shares_count];
    self.commentButton.titleLabel.text = [NSString stringWithFormat:@"%zd",self.guideDetail.comments_count];
    
}

- (IBAction)likeButtonOnClick:(UIButton *)sender {
    
    NSInteger likeCount = sender.selected ? self.guideDetail.likes_count + 1 : self.guideDetail.likes_count - 1;
//    GTLog(@"likeCount: %ld, +1 : %ld",likeCount, likeCount + 1);
    self.likeButton.titleLabel.text = [NSString stringWithFormat:@"%ld",likeCount];
    sender.selected = !sender.selected;
}

- (IBAction)shareButtonOnClick:(UIButton *)sender {
    UIViewController *rootVc = [UIApplication sharedApplication].keyWindow.rootViewController;
    [GTUMSocialShare shareByPresentVc:rootVc shareImage:[UIImage imageNamed:@"post_sharebutton_highlighted"] shareDescription:nil shareUrl:nil];
}

- (IBAction)commentButtonOnClick:(UIButton *)sender {
    GTLogFunc
}
@end
